home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / pgp23src.zip / SRC / PGP.H < prev    next >
C/C++ Source or Header  |  1993-06-11  |  10KB  |  257 lines

  1. /*
  2.     Pretty Good(tm) Privacy - RSA public key cryptography for the masses
  3.     Written by Philip Zimmermann, Phil's Pretty Good(tm) Software.
  4.     Version 1.0 - 5 Jun 91, last revised 6 Jul 91 by PRZ
  5.  
  6.     This file defines the various formats, filenames, and general control
  7.     methods used by PGP, as well as a few global switches which control
  8.     the functioning of the driver code.
  9.  
  10. */
  11.  
  12. #include "usuals.h"
  13. #include "more.h"
  14. #include "armor.h"
  15.  
  16. #define KEYFRAGSIZE 8    /* # of bytes in key ID modulus fragment */
  17. #define SIZEOF_TIMESTAMP 4 /* 32-bit timestamp */
  18.  
  19. /* The maximum length of the file path for this system.  Varies on UNIX
  20.    systems */
  21.  
  22. #ifndef    MAX_PATH
  23. #ifdef MSDOS
  24. #define MAX_PATH    64
  25. #else
  26. #define MAX_PATH    256
  27. #endif
  28. #endif
  29.  
  30. #ifdef ATARI
  31. #define sizeof(x) (int)sizeof(x)
  32. #define fread(a,b,c,d)    ((int)fread(a,b,c,d))
  33. #endif
  34.  
  35. /*
  36. **********************************************************************
  37. */
  38.  
  39. /* Cipher Type Byte (CTB) definitions follow...*/
  40. #define CTB_DESIGNATOR 0x80
  41. #define is_ctb(c) (((c) & CTB_DESIGNATOR)==CTB_DESIGNATOR)
  42. #define CTB_TYPE_MASK 0x7c
  43. #define CTB_LLEN_MASK 0x03
  44.  
  45. /* "length of length" field of packet, in bytes (1, 2, 4, 8 bytes): */
  46. #define ctb_llength(ctb) ((int) 1 << (int) ((ctb) & CTB_LLEN_MASK))
  47.  
  48. #define is_ctb_type(ctb,type) (((ctb) & CTB_TYPE_MASK)==(4*type))
  49. #define CTB_BYTE(type,llen) (CTB_DESIGNATOR + (4*type) + llen)
  50.  
  51. #define CTB_PKE_TYPE 1            /* packet encrypted with RSA public key */
  52. #define CTB_SKE_TYPE 2            /* packet signed with RSA secret key */
  53. #define CTB_MD_TYPE 3            /* message digest packet */
  54. #define CTB_CERT_SECKEY_TYPE 5  /* secret key certificate */
  55. #define CTB_CERT_PUBKEY_TYPE 6  /* public key certificate */
  56. #define CTB_COMPRESSED_TYPE 8    /* compressed data packet */
  57. #define CTB_CKE_TYPE 9            /* conventional-key-encrypted data */
  58. #define    CTB_LITERAL_TYPE 10        /* raw data with filename and mode */
  59. #define CTB_LITERAL2_TYPE 11    /* Fixed literal packet */
  60. #define CTB_KEYCTRL_TYPE 12        /* key control packet */
  61. #define CTB_USERID_TYPE 13        /* user id packet */
  62. #define CTB_COMMENT_TYPE 14        /* comment packet */
  63.  
  64. /* Unimplemented CTB packet types follow... */
  65. /* #define CTB_EXTENDED_TYPE 15 */ /* 2-byte CTB, 256 extra CTB types */
  66.  
  67. #define CTB_PKE CTB_BYTE(CTB_PKE_TYPE,1)
  68.     /* CTB_PKE len16 keyID mpi(RSA(CONKEYPKT)) */
  69.     /*      1         2     SIZE  countbytes()+2 */
  70. #define CTB_SKE CTB_BYTE(CTB_SKE_TYPE,1)
  71.     /* CTB_SKE len16 keyID mpi(RSA(MDPKT)) */
  72.     /*      1         2     SIZE  countbytes()+2 */
  73. #define CTB_MD CTB_BYTE(CTB_MD_TYPE,0)
  74.     /* CTB_MD len8 algorithm MD timestamp */
  75. #define CTB_CERT_SECKEY CTB_BYTE(CTB_CERT_SECKEY_TYPE,1)
  76.     /* CTB_CERT_SECKEY len16 timestamp userID mpi(n) mpi(e) mpi(d) mpi(p) mpi(q) mpi(u) crc16 */
  77. #define CTB_CERT_PUBKEY CTB_BYTE(CTB_CERT_PUBKEY_TYPE,1)
  78.     /* CTB_CERT_PUBKEY len16 timestamp userID mpi(n) mpi(e) crc16 */
  79.  
  80. #define CTB_KEYCTRL CTB_BYTE(CTB_KEYCTRL_TYPE,0)
  81. #define    CTB_USERID    CTB_BYTE(CTB_USERID_TYPE,0)
  82.  
  83. #define CTB_CKE CTB_BYTE(CTB_CKE_TYPE,3)
  84.     /*    CTB_CKE ciphertext */
  85.  
  86. #define CTB_LITERAL CTB_BYTE(CTB_LITERAL_TYPE,3)
  87. #define CTB_LITERAL2 CTB_BYTE(CTB_LITERAL_TYPE,3)
  88.     /*    CTB_LITERAL data */
  89.  
  90. #define CTB_COMPRESSED CTB_BYTE(CTB_COMPRESSED_TYPE,3)
  91.     /*    CTB_COMPRESSED compressedtext */
  92.  
  93. /*    Public key encryption algorithm selector bytes. */
  94. #define RSA_ALGORITHM_BYTE    1    /*    use RSA    */
  95.  
  96. /*    Conventional encryption algorithm selector bytes. */
  97. #define IDEA_ALGORITHM_BYTE    1    /*    use the IDEA cipher */
  98.  
  99. /*    Message digest algorithm selector bytes. */
  100. #define MD5_ALGORITHM_BYTE 1    /* MD5 message digest algorithm */
  101.  
  102. /*    Data compression algorithm selector bytes. */
  103. #define ZIP2_ALGORITHM_BYTE  1    /* Zip-based deflate compression algorithm */
  104.  
  105. /* Signature classification bytes. */
  106. #define SB_SIGNATURE_BYTE    0x00    /* Signature of a binary msg or doc */
  107. #define SM_SIGNATURE_BYTE    0x01    /* Signature of canonical msg or doc */
  108. #define    K0_SIGNATURE_BYTE    0x10    /* Key certification, generic */
  109. #define    K1_SIGNATURE_BYTE    0x11    /* Key certification, persona */
  110. #define    K2_SIGNATURE_BYTE    0x12    /* Key certification, casual ID */
  111. #define    K3_SIGNATURE_BYTE    0x13    /* Key certification, positive ID */
  112. #define KC_SIGNATURE_BYTE    0x20    /* Key compromise */
  113. #define KR_SIGNATURE_BYTE    0x30    /* Key revocation */
  114. #define    TS_SIGNATURE_BYTE    0x40    /* Timestamp someone else's signature */
  115.  
  116. /* Public key encrypted data classification bytes. */
  117. #define MD_ENCRYPTED_BYTE    1    /* Message digest is encrypted */
  118. #define CK_ENCRYPTED_BYTE    2    /* Conventional key is encrypted */
  119.  
  120. /* Version byte for data structures created by this version of PGP */
  121. #define    VERSION_BYTE        2    /* PGP2 */
  122.  
  123. /* Values for trust bits in keycntrl packet after key packet */
  124. #define    KC_OWNERTRUST_MASK        0x07    /* Trust bits for key owner */
  125. #define    KC_OWNERTRUST_UNDEFINED    0x00
  126. #define    KC_OWNERTRUST_UNKNOWN    0x01
  127. #define    KC_OWNERTRUST_NEVER        0x02
  128. /* 2 levels reserved */
  129. #define    KC_OWNERTRUST_USUALLY    0x05
  130. #define    KC_OWNERTRUST_ALWAYS    0x06
  131. #define    KC_OWNERTRUST_ULTIMATE    0x07    /* Only for keys in secret ring */
  132. #define    KC_BUCKSTOP                0x80    /* This key is in secret ring */
  133. #define    KC_VISITED                0x40
  134. #define    KC_DISABLED                0x20    /* key is disabled */
  135.  
  136. /* Values for trust bits in keycntrl packet after userid packet */
  137. #define    KC_LEGIT_MASK            0x03    /* Key legit bits for key */
  138. #define    KC_LEGIT_UNKNOWN        0x00
  139. #define KC_LEGIT_UNTRUSTED        0x01
  140. #define KC_LEGIT_MARGINAL        0x02
  141. #define    KC_LEGIT_COMPLETE        0x03
  142. #define    KC_WARNONLY                0x80
  143.  
  144. /* Values for trust bits in keycntrl packet after signature packet */
  145. #define    KC_SIGTRUST_MASK        0x07    /* Trust bits for key owner */
  146. #define    KC_SIGTRUST_UNDEFINED    0x00
  147. #define    KC_SIGTRUST_UNKNOWN        0x01
  148. #define    KC_SIGTRUST_UNTRUSTED    0x02
  149. /* 2 levels reserved */
  150. #define    KC_SIGTRUST_MARGINAL    0x05
  151. #define    KC_SIGTRUST_COMPLETE    0x06
  152. #define    KC_SIGTRUST_ULTIMATE    0x07
  153. #define    KC_SIG_CHECKED            0x40    /* This sig has been checked */
  154. #define    KC_CONTIG                0x80    /* This sig is on a cert. path */
  155.  
  156. #define is_secret_key(ctb) is_ctb_type(ctb,CTB_CERT_SECKEY_TYPE)
  157.  
  158. #define MPILEN (2+MAX_BYTE_PRECISION)
  159. #define MAX_SIGCERT_LENGTH (1+2+1 +1+7 +KEYFRAGSIZE+2+2+MPILEN)
  160. #define MAX_KEYCERT_LENGTH (1+2+1+4+2+1 +(2*MPILEN) +1+8 +(4*MPILEN) +2)
  161.  
  162. /* Modes for CTB_LITERAL2 packet */
  163. #define    MODE_BINARY    'b'
  164. #define    MODE_TEXT    't'
  165. #define MODE_LOCAL    'l'
  166.  
  167. /* Define CANONICAL_TEXT for any system which normally uses CRLF's
  168.    for text separators */
  169. #ifdef MSDOS
  170. #define    CANONICAL_TEXT
  171. #endif /* MSDOS */
  172.  
  173. /* Prototype for the 'more' function, which blorts a file to the screen with
  174.    page breaks, intelligent handling of line terminators, truncation of
  175.    overly long lines, and zapping of illegal chars.  Implemented in MORE.C */
  176.  
  177. int more_file(char *fileName);
  178.  
  179. /* Prototypes for the transport armor routines */
  180.  
  181. boolean is_armor_file(char *infile, long startline);
  182. int armor_file(char *infile, char *outfile, char *filename, char *clearname);
  183. int de_armor_file(char *infile, char *outfile, long *curline);
  184.  
  185. void user_error(void);
  186.  
  187. /* Global filenames and system-wide file extensions... */
  188. extern char PGP_EXTENSION[];
  189. extern char ASC_EXTENSION[];
  190. extern char SIG_EXTENSION[];
  191. extern char BAK_EXTENSION[];
  192. extern char CONSOLE_FILENAME[];
  193. extern char rel_version[];
  194.  
  195. /* These files use the environmental variable PGPPATH as a default path: */
  196. extern char PUBLIC_KEYRING_FILENAME[32];
  197. extern char SECRET_KEYRING_FILENAME[32];
  198. extern char RANDSEED_FILENAME[32];
  199.  
  200. /* Variables which are global across the driver code */
  201. extern boolean    filter_mode;
  202. extern boolean    moreflag;
  203. extern FILE    *pgpout;    /* FILE structure for routine output */
  204.  
  205. /* Variables settable by config.pgp and referenced in config.c ... */
  206. extern char language[];    /* foreign language prefix code for language.pgp file */
  207. extern char charset[];
  208. /* my_name is substring of default userid for secret key to make signatures */
  209. extern char my_name[];
  210. extern char floppyring[]; /* for comparing secret keys with backup on floppy */
  211. extern char literal_mode;    /* text or binary mode for literal packet */
  212. extern boolean emit_radix_64;
  213. extern boolean showpass;
  214. extern boolean keepctx;
  215. extern boolean verbose;    /* display maximum information */
  216. extern boolean compress_enabled;    /* attempt compression before encryption */
  217. extern boolean clear_signatures;
  218. extern boolean encrypt_to_self; /* Should I encrypt to myself? */
  219. extern boolean batchmode;    /* for batch processing */
  220. extern boolean quietmode;    /* less verbose */
  221. extern boolean force_flag;    /* overwrite existing file without asking */
  222. extern boolean pkcs_compat;    /* Use PKCS format messages */
  223. /* Ask for each key separately if it should be added to the keyring */
  224. extern boolean interactive_add;
  225. extern long timeshift;    /* seconds from GMT timezone */
  226. extern boolean signature_checked;
  227. extern int pem_lines;
  228. extern int marg_min;    /* number of marginally trusted signatures needed to
  229.                            make a key fully-legit */
  230. extern int compl_min;    /* number of fully trusted signatures needed */
  231. extern int max_cert_depth;
  232. extern char pager[];    /* file lister command */
  233.  
  234. /* These lists store hashed passwords for future use. */
  235. /* passwds are passwords of as-yet-unknown purpose; keypasswds
  236.    are passwords used to decrypt keys. */
  237. struct hashedpw {
  238.     struct hashedpw *next;
  239.     byte hash[16];
  240. };
  241. extern struct hashedpw *keypasswds, *passwds;
  242.  
  243. extern boolean strip_spaces;
  244.  
  245. #ifdef VMS
  246. /*
  247.  * FDL Support Prototypes, Currently Used Only In SYSTEM.C and CRYPTO.C
  248.  */
  249.  
  250. int fdl_generate(char *in_file, char **fdl, short *len);
  251. VOID *fdl_create( char *fdl, short len, char *outfile, char *preserved_name);
  252. int fdl_copyfile2bin(FILE *f, VOID *rab, word32 longcount); 
  253. void fdl_close( VOID *rab);
  254. #endif /* VMS */
  255.  
  256. extern int compressSignature(byte *header);
  257.